//
//  MeCollectionHeaderView.m
//  HTHappySale
//
//  Created by 创维海通 on 2017/9/20.
//  Copyright © 2017年 zxyywy. All rights reserved.
//

#import "MeCollectionHeaderView.h"

//Tools
#import "UIImageView+WebCache.h"

@interface MeCollectionHeaderView ()
@property (strong, nonatomic) IBOutlet UIImageView *headImg;
@property (strong, nonatomic) IBOutlet UILabel *nickLabel;

@property (strong, nonatomic) NSString *ImgStr;

@end

@implementation MeCollectionHeaderView

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backgroundColor = [UIColor colorWithPatternImage:HTCFQuickImage(@"income_banner_bg")];
    
    NSString *filePath = HTCFAppCacheDirectory;
    NSString *filePath2 = [NSString stringWithFormat:@"%@%@",filePath,@"/MyImage/pic.png"];

    if (!HTCFCheckObjectNull(kPortraitKey)) {
        _ImgStr = [NSString stringWithFormat:@"%@%@",Img_URL,HTCFUDFGetValue(kPortraitKey)];
    }

    if(HTCFFileIsExist(filePath2)){
        NSData *data = [NSData dataWithContentsOfFile:filePath2];

        UIImage *image = [UIImage imageWithData:data];
        [_headImg setImage:image];
    }else if (_ImgStr != nil && _ImgStr.length >0)
    {
        [_headImg sd_setImageWithURL:[NSURL URLWithString:_ImgStr] placeholderImage:HTCFQuickImage(@"Headportrait")];
    }else{
        _headImg.image = HTCFQuickImage(@"Headportrait");
    }
    _headImg.layer.masksToBounds = YES;
    _headImg.layer.cornerRadius = 35;
    
    NSLog(@"nickname:%@",HTCFUDFGetValue(kNickNameKey));
    if(!HTCFCheckObjectNull(kNickNameKey))
    {
        nickname = HTCFUDFGetValue(kNickNameKey);
    }
    
    _nickLabel.text = nickname;
    
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapAction = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(NextWindow:)];
    [self addGestureRecognizer:tapAction];
}

- (void)NextWindow:(UITapGestureRecognizer *)sender
{
    if (self.headerDelegate && [self.headerDelegate respondsToSelector:@selector(NextController)])
    {
        [self.headerDelegate NextController];
    }
}

@end
